<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 只能在一天买入，一天卖出。所以根本没必要dp，只需要遍历完一遍，找出前面最低成本，然后计算利润即可
             */
            var maxProfit = function (prices) {
                let minCost = prices[0]
                let profit = 0
                for (let i = 0; i < prices.length; i++) {
                    minCost = Math.min(minCost, prices[i])
                    profit = Math.max(profit, prices[i] - minCost)
                }
                return profit
            }
        </script>
    </body>
</html>
